package cn.com.dhc.danlu.widget.adapter;

import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import java.util.List;

import cn.com.dhc.danlu.widget.CustomAbstractListView;

/**
 * Abstract ListAdapter.
 *
 * @author guodong@dhc.com.cn
 */
public abstract class CustomAbstractListAdapter <Item> extends BaseAdapter {

    /**
     * activity
     */
    protected CustomAbstractListView listView = null;
    /**
     * inflater
     */
    LayoutInflater layoutInflater;
    /**
     * item list
     */
    private List<Item> itemList = null;

    CustomAbstractListAdapter(CustomAbstractListView listView, List<Item> model) {
        super();
        this.listView = listView;
        this.itemList = model;
//        layoutInflater = LayoutInflater.from(listView.getDelegate().getActivity());
        layoutInflater = LayoutInflater.from(listView.getContext());
    }

    @Override
    public int getCount() {
        return (itemList == null) ? 0 : itemList.size();
    }

    @Override
    public Object getItem(int position) {
        return itemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean isEmpty() {
        return (itemList == null) || itemList.isEmpty();
    }

    public CustomAbstractListView getListView() {
        return listView;
    }

    public List<Item> getItemList() {
        return itemList;
    }
}
